package com.landary.parameterrplacement.entity;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.*;

/**
 * @author 刘欣
 * @createTime 2023/8/14 14:08
 * @description
 */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Post {
    private String avicSimpleTitle;

    private List<String> persons;

    /**
     * 获取岗位类型
     * @param mapList
     * @return
     */
    public static Set<String> mapToPostList(List<Map<String, String>> mapList) {
        Set<String> postSet = new HashSet<>();
        for (Map<String, String> map : mapList) {
            String avicSimpleTitle = map.get("avicSimpleTitle");
            if (avicSimpleTitle != null && avicSimpleTitle != "") {
                postSet.add(avicSimpleTitle);
            }

        }
        return postSet;
    }

    /**
     * 岗位下的用户
     * @param mapList
     * @return
     */
    public static List<Post> getPost(List<Map<String, String>> mapList) {
        Set<String> postSet = mapToPostList(mapList);
        List<Post> posts = new ArrayList<>();
        for (String postName : postSet) {
            Post post = new Post();
            List<String> avicUserAccounts = new ArrayList<>();
            post.setAvicSimpleTitle(postName);
            for (Map<String, String> map : mapList) {
                if (postName.equals(map.get("avicSimpleTitle"))) {
                    avicUserAccounts.add("person:" + map.get("avicUserAccount"));
                }
            }
            post.setPersons(avicUserAccounts);
            posts.add(post);
        }
        return posts;
    }
}
